package com.xyht.sca_s.student_manage_system.modules.bigData.controller;

import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonCodeEnum;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonResult;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.bigData.service.SmsTeachersPowerService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
import java.util.concurrent.Future;

/**
 * <p>
 *  大数据驾驶舱-校园总览-师资力量 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-08-31
 */
@RestController
@RequestMapping("/bigData/teacherPower")
@SecretBody
public class SmsTeachersPowerController {
    @Resource
    private SmsTeachersPowerService smsTeachersPowerService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiModelProperty(value = "师资力量批量导入")
    @PostMapping("/batch/add")
    public ResponseResult batchAddEnrolStudent(@RequestBody Map<String,Object> map, HttpServletRequest request){
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        ResponseResult commonCodeEnum;
        try{
            Future<ResponseResult> future = smsTeachersPowerService.batchAddTeachersPower(map,user_id);
            while (true){
                if (future.isDone()){
                    commonCodeEnum = future.get();
                    break;
                }
            }
        }catch (Exception e){
            e.printStackTrace();
            return CommonResult.failed(CommonCodeEnum.FAIL);
        }
        return commonCodeEnum;
    }
    @ApiModelProperty("教师数量+教师学历+教师获奖信息")
    @GetMapping("/getTeachersPower")
    public ResponseResult getTeachersPower(){
        return smsTeachersPowerService.getTeachersPower();
    }


    @ApiModelProperty("出勤概况")
    @GetMapping("/getAttendanceOverview")
    public ResponseResult getAttendanceOverview(@RequestParam(value = "type",required = false) Integer type,
                                                @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum){
        return smsTeachersPowerService.getAttendanceOverview(type,pageNum,pageSize);
    }

}
